<template>
  <div class="Withdrawal_application" v-if="status">
    <div class="Withdrawal_application_top">
      <span> 温馨提示：申请提交后不可撤回，请谨慎提交！</span>
    </div>
    <div class="Withdrawal_application_bottom">
      <el-form
        :model="form"
        :label-position="labelPosition"
        label-width="100px"
      >
        <el-form-item label="申请人">
          <el-input disabled v-model="form.pricipalName"></el-input>
        </el-form-item>

        <el-form-item label="团队名称">
          <el-input disabled v-model="form.teamName"></el-input>
        </el-form-item>

        <el-form-item label="退出理由" id="withdrawal_reason">
          <el-input
            v-model="form.reason"
            placeholder="退出理由"
            type="textarea"
          ></el-input>
        </el-form-item>

        <div class="Withdrawal_application_Submit">
          <el-button @click="Submit_form">提交</el-button>
          <el-button @click="empty_form">取消</el-button>
        </div>
      </el-form>
    </div>
  </div>
  <div v-else class="Withdrawal_application">
    <div class="Withdrawal_application_top">
      <span> 您已提交退出申请！</span>
    </div>
    <el-steps
      direction="vertical"
      :space="200"
      :active="steps.procedure"
      :align-center="true"
    >
      <el-step
        :title="steps.step1.title"
        :status="steps.step1.status"
      ></el-step>

      <el-step
        :title="steps.step2.title"
        :status="steps.step2.status"
        v-if="steps.step2.status == 'success'"
      ></el-step>
      <el-step
        :title="steps.step2.title"
        icon="el-icon-loading"
        :status="steps.step2.status"
        v-else
      ></el-step>
      <el-step :title="steps.step3.title" :status="steps.step3.status">
        <a href="">申请</a>
      </el-step>
      <a
        @click="status = true"
        v-if="steps.step3.status == 'error'"
        id="Reapply"
        >重新申请</a
      >
    </el-steps>
  </div>
</template>

<script>
export default {
  props: {},
  components: {},
  data() {
    return {
      steps: {
        procedure: 1,
        step1: "",
        step2: "",
        step3: "",
      },
      labelPosition: "right",
      status: false,
      form: {
        pricipalName: " ",
        teamName: "xx团队",
        reason: "",
      },
    };
  },
  methods: {
    async Submit_form() {
      const self = this;

      const { data: res } = await this.$http({
        headers: { "Content-Type": "application/json;charset=UTF-8" },
        method: "post",
        url: "/api/applyLeave/addApplyLeave",
        pararm: { description: self.form.reason },
      });
      console.log(res);
      if (res.code != 200) {
        this.$message.error("提交失败");
      }

      this.$message.success("提交成功");
      this.status = false;
      this.form.reason = "";
    },
    empty_form() {
      this.form.reason = "";
    },

    keyDown(e) {
      //如果是回车则执行登录方法
      if (e.keyCode == 13) {
        this.Submit_form();
        return;
      }
    },
  },
  mounted() {
    //绑定事件
    window.addEventListener("keydown", this.keyDown);
  },
  destroyed() {
    window.removeEventListener("keydown", this.keyDown);
  },
  async created() {
    this.form.pricipalName = window.localStorage.getItem("name");
    console.log(this.form.pricipalName);
    this.form.teamName = window.sessionStorage.getItem("TeamName");
    const { data: res } = await this.$http({
      headers: { "Content-Type": "application/json;charset=UTF-8" },
      method: "get",
      url: "/api/apply/getLeaveStatus",
    });
    if (res.code != 200) {
      this.status = true;
    } else {
      this.status = false;
      if (res.msg.applyStatus == 0) {
        this.steps.procedure = 1;
        this.steps.step1 = { title: "提交退出申请 ", status: "success" };
        this.steps.step2 = { title: "待审核 ", status: "process" };
        this.steps.step3 = { title: "审核结果公布 ", status: "wait" };
      }
      if (res.msg.applyStatus == 1) {
        this.steps.procedure = 3;
        this.steps.step1 = { title: "提交退出申请 ", status: "success" };
        this.steps.step2 = { title: "已审核 ", status: "success" };
        this.steps.step3 = { title: "同意退出 ", status: "success" };
      }
      if (res.msg.applyStatus == -1) {
        this.steps.procedure = 3;
        this.steps.step1 = { title: "提交退出申请 ", status: "success" };
        this.steps.step2 = { title: "已审核 ", status: "success" };
        this.steps.step3 = { title: "已驳回 ", status: "error" };
      }
    }
  },
};
</script>

<style lang="less">
.Withdrawal_application {
  // background-color: rgb(167, 19, 19);
  height: 98%;
  width: 100%;
  margin: 10px;
  display: flex;
  flex-direction: column;
  .el-steps {
    width: 10%;
    display: flex;
    height: 600px;
    margin: auto;
  }
}
.Withdrawal_application_top {
  display: flex;
  height: 80px;
  span {
    border-radius: 10px;
    width: 900px;
    background-color: rgb(229, 240, 255);
    margin: auto;
    text-align: center;
    height: 50px;
    line-height: 50px;
  }
}
.Withdrawal_application_bottom {
  margin: 15px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 10px rgba(0, 0, 0, 0.04);
  height: 90%;
  width: 98%;
  display: flex;
  flex-direction: column;
  .el-form {
    display: flex;
    flex-direction: column;
    height: 600px;
    width: auto;

    margin: auto;
    margin-top: 30px;
    .el-form-item {
      display: flex;
      flex-direction: row;
      height: 100px;
      .el-form-item__label {
        font-size: 20px;
        height: 60px;
        line-height: 60px;
        font-weight: bold;
      }
      .el-input {
        width: 900px;

        .el-input__inner {
          height: 60px;
          font-size: 19px;
        }
      }
    }
  }
}
#withdrawal_reason {
  display: flex;
  flex-direction: row;
  height: 200px;
  .el-textarea__inner {
    display: flex;
    width: 900px;
    font-size: 25px;
    height: 200px;
  }
}
.Withdrawal_application_Submit {
  height: 100px;
  width: auto;
  display: flex;
  margin: 0px auto;
  button {
    height: 50px;
    width: 200px;
    border: none;
  }
  button:nth-child(1) {
    background-color: rgb(0, 110, 255);
    color: #fff;
    font-size: 20px;
    font-weight: bolder;
  }
  button:nth-child(2) {
    background-color: rgb(242, 242, 242);
    margin-left: 150px;
    font-size: 20px;
  }
}
#Reapply {
  color: rgb(0, 110, 255);
  cursor: pointer;
}
</style>